package com.example.eduservice.controller.front;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.eduservice.entity.EduCourse;
import com.example.eduservice.entity.EduTeacher;
import com.example.eduservice.service.EduCourseService;
import com.example.eduservice.service.EduTeacherService;
import com.example.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;


//@CrossOrigin
@RestController
@RequestMapping("/eduservice/teacherfront")
public class TeacherFrontController {

    @Autowired
    private EduTeacherService teacherService;

    @Autowired
    private EduCourseService courseService;


    //讲师列表功能
    @PostMapping("/getTeacherFrontList/{page}/{limit}")
    public R getTeacherFrontLsit(@PathVariable long page, @PathVariable long limit){

        Page<EduTeacher> teacherPage=new Page<>(page,limit);
          Map<String,Object> map=teacherService.getTeacherFrontList(teacherPage);
          //返回map集合
           return  R.ok().data(map);
    }

    //讲师详情功能
    @GetMapping("/getTeacherFrontInfo/{teacherid}")
    public  R  getTeacherFrontInfo(@PathVariable String teacherid){
        //查询讲师
        EduTeacher eduTeacher = teacherService.getById(teacherid);

        //根据讲师id查课程
        QueryWrapper<EduCourse> wrapper=new QueryWrapper<>();
        wrapper.eq("teacher_id",teacherid);
        //查询讲师有那些课程
        List<EduCourse> courseList = courseService.list(wrapper);

        return  R.ok().data("teacher",eduTeacher).data("courseList",courseList);


    }


}
